<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理-登陆</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="lib/layui-v2.5.4/css/layui.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {background:url("images/bg.jpg") repeat;background-size:cover;min-height:100vh;width:100%;}
        #container{height:100%;width:100%;}
        input:-webkit-autofill {-webkit-box-shadow:inset 0 0 0 1000px #fff;background-color:transparent;}
        .admin-login-background {width:400px;height:300px;position:absolute;left:50%;top:40%;margin-left:-200px;margin-top:-100px;}
        .admin-header {text-align:center;margin-bottom:20px;color:#ffffff;font-weight:bold;font-size:40px}
        .admin-input {border-top-style:none;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;height:50px;padding-bottom:0px;}
        .admin-input::-webkit-input-placeholder {color:#078e17}
        .layui-icon-username {color:#078e17 !important;}
        .layui-icon-username:hover {color:#9dadce !important;}
        .layui-icon-password {color:#078e17 !important;}
        .layui-icon-password:hover {color:#9dadce !important;}
        .admin-button {font-weight:bold;font-size:18px;width:100%;height:50px;background-color:#078e17;margin-top:20px}
        .admin-icon {margin-left:90%;margin-top:10px;font-size:30px;}
        i {position:absolute;}
    </style>
</head>
<body>
<div id="container">
    <div></div>
    <div class="admin-login-background">
        <div class="admin-header">
            <span>后台登录</span>
        </div>
        <div class="layui-form">
            <div>
                <i class="layui-icon layui-icon-username admin-icon"></i>
                <input type="text" name="phone" placeholder="手机号" 
                 class="layui-input admin-input admin-input-username">
            </div>
            <div>
                <i class="layui-icon layui-icon-password admin-icon"></i>
                <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input admin-input">
            </div>
            <div>
                <button class="layui-btn admin-button" lay-submit lay-filter="login">登 陆</button>
            </div>

        </div>
    </div>
</div>
<script src="lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="js/lay-config.js" charset="utf-8"></script>

<script>
    layui.use(['form','vCache','http','layer'], function () {
        const form = layui.form,
            layer = layui.layer,
            http = layui.http,
            $ = layui.jquery;
       if( layui.vCache.lGet('X-token') ){
           window.location = AdminPath+'/i.html';
       }        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            if (data.phone === '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password === '') {
                layer.msg('密码不能为空');
                return false;
            }
          http.post('/admin/login.htm',{data}).done(function(res){
              layer.msg(res.msg);
              if(res.code === 200){
                  setTimeout(() => {
                            window.location.href = AdminPath+'/i.html'
                    }, 1200);
                 if(res.result.token){
                     layui.vCache.lSet('X-token',res.result.token)
                 }
                 if(res.result.menu) {
                     layui.vCache.lSet('menu_data',res.result.menu)
                 }
                 if(res.result.group ){
                     layui.vCache.lSet('group_data', res.result.group)
                 }
              }
          })
        });
    });
</script>
</body>
</html>